package com.upic.serviceImpl;

import com.upic.po.Notice;
import com.upic.repository.NoticeRepository;
import com.upic.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YeTian
 * @date 2018/2/7/007
 */
@Service("noticeService")
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeRepository noticeRepository;

    @Override
    public Notice saveNotice(Notice notice) {
        return noticeRepository.save(notice);
    }

    @Override
    public String deleteNotice(long noticeId) {
        noticeRepository.delete(noticeId);
        return "SUCCESS";
    }

    @Override
    public Page<Notice> searchNotice(Pageable pageable) {
        return noticeRepository.findAll(pageable);
    }

    @Override
    public List<Notice> searchNotice() {
        return noticeRepository.findAll();
    }

    @Override
    public Notice findOne(long noticeId) {
        return noticeRepository.findOne(noticeId);
    }

    @Override
    public Notice updateNotice(Notice notice) {
        return noticeRepository.saveAndFlush(notice);
    }
}
